#pragma once

#include <iostream>
#include <unistd.h>
#include <semaphore.h>

namespace Local_Sem
{
    class LocalSem
    {
    public:
        LocalSem(int capacity)
            : _capacity(capacity)
        {
            sem_init(&_sem, 0, _capacity);
        }
        ~LocalSem()
        {
            sem_destroy(&_sem);
        }
        // P操作 --
        void P()
        {
            sem_wait(&_sem);
        }
        // V操作 ++
        void V()
        {
            sem_post(&_sem);
        }

    private:
        sem_t _sem;
        int _capacity;
    };
}
